/* 
 * File:   Loader3DS.h
 * Author: gilvolpe
 *
 * Created on June 8, 2013, 9:59 AM
 */

#ifndef LOADER3DS_H
#define	LOADER3DS_H

#include "basicInformation.h"
#include <sys/stat.h>
#include "Vector.h"
#include "Texture.h"

#define MAX_VERTICES 80000 // Max number of vertices (for each object)
#define MAX_POLYGONS 80000 // Max number of polygons (for each object)

typedef struct {
    float x, y, z;
} vertex_type;

// The polygon (triangle), 3 numbers that aim 3 vertices

typedef struct {
    int a, b, c;
} polygon_type;

// The mapcoord type, 2 texture coordinates for each vertex

typedef struct {
    float u, v;
} mapcoord_type;

typedef struct {
    char name[20];

    int vertices_qty;
    int polygons_qty;

    vertex_type vertex[MAX_VERTICES];
    vertex_type normal[MAX_VERTICES];
    polygon_type polygon[MAX_POLYGONS];
    mapcoord_type mapcoord[MAX_VERTICES];
    int id_texture;

} obj_type, *obj_type_ptr;

class Loader3DS {
public:
    static void read3DSextension(obj_type_ptr obj,char *elem3DS);
private:
    static long filelength(int f);
    static char load3DS(obj_type_ptr p_object, char *p_filename);
    static void setNormals(obj_type_ptr p_object);
    
    static Texture tex;
};

#endif	/* LOADER3DS_H */

